package org.example.leetCode;

import java.util.HashMap;

/**
 * @author Vader
 * @date 2021/11/5
 **/
public class NumIdenticalPairs {
    public int numIdenticalPairs(int[] nums) {
        if (nums.length < 2) {
            return 0;
        }
        HashMap<Integer, Integer> map = new HashMap<>();
        int result = 0;
        for (int num : nums) {
            Integer integer = map.get(num);
            if (integer != null) {
                map.put(num, integer + 1);
                result += integer;
            } else {
                map.put(num, 1);
            }
        }
        return result;
    }
}
